(function ($) {
    $.extend(true, window, {
        Slick: {
            ResponsiveColumns: ResponsiveColumns
        }
    });


    /***
    * Provides item metadata for group (Slick.Group) and totals (Slick.Totals) rows produced by the DataView.
    * This metadata overrides the default behavior and formatting of those rows so that they appear and function
    * correctly when processed by the grid.
    *
    * This class also acts as a grid plugin providing event handlers to expand & collapse groups.
    * If "grid.registerPlugin(...)" is not called, expand & collapse will not work.
    *
    * @class GroupItemMetadataProvider
    * @module Data
    * @namespace Slick.Data
    * @constructor
    * @param options
    */
    function ResponsiveColumns(options) {
        var _grid;

        function init(grid) {
            _grid = grid;
            var columns = _grid.getColumns();
            //$.extend(_grid, { responsive: { columns:columns} });

            _grid.$control.resize(function (event) {
                var visibleColumns = [];
                for (var i = 0; i < columns.length; i++) {
                    if (!columns[i].hideAt || _grid.$control.width() > columns[i].hideAt) {
                        visibleColumns.push(columns[i]);
                    }
                }
                if (visibleColumns.length != _grid.getColumns().length) {
                    _grid.setColumns(visibleColumns);
                    _grid.updateHeaderRow();
                }
            });
        }

        function destroy() {
            if (_grid) {
                _grid.onClick.unsubscribe(handleGridClick);
                _grid.onKeyDown.unsubscribe(handleGridKeyDown);
            }
        }


        return {
            "init": init,
            "destroy": destroy
        };
    }
})(jQuery);